<!-- Note: Everything in this page can be replaced with the text that you want on the main page i.e. this is the 'homebody.html' page that is included in the template - so this will be the main page text for the right side -->

<?php 
session_start();
 if (isset($_REQUEST["postback"]))
 { 
   include "common.php";
   include("./validation/php/FormValidator.class.inc");
   if( $_SESSION['security_code'] == $_REQUEST['security_code'] && !empty($_SESSION['security_code'] ) ) 
	 {
	    $email =$_REQUEST["email"];
	    $password =$_REQUEST["password"];
	    $short_name =$_REQUEST["shortname"];
			    
			$fv = new FormValidator();
			
			$fv->isEmailAddress("email", "invalid email address");
			$fv->isAlpha("password", "invalid password");
			$fv->isAlpha("short_name", "Invalid short name");
			// and so on
			$fv->isError();
			$errors = $fv->getErrorList();
			if(count($errors) > 0)
			{
									echo "<div class ='error_heading'>Errors exists, correct before submitting <br/></div>";
									echo "<div class= 'error'>";
									while( $error = each( $errors ) )
									{
									  
									  echo  $error[1]['field']. '&nbsp;&nbsp; is  ';
									  echo $error[1]['msg'];
			            	echo "<br />";
			            	}
			            	echo "</div> <br />";
			           /* //commented code works as reference of using arrays in php. 
								    //I struggled for some 30 minutes to understand how to retrive array values
										foreach ($errors as $key => $error)
								  	{
			            	echo $key.'=>'.$value.'<br />';
			       
								 while( $element = each( $error ) )
										{
											 echo $element[ 'value' ];
											 echo ' - ';
											 echo $element[ 'msg' ];
											 echo '<br />';
											}
			           
			          //  }
			          */
									generate_form();
			  $fv->resetErrorList();
			}
			else
			{
				  $query = "insert into login_master(email_id,pwd,shortname)values('$email','$password','$short_name')";
 				  //echo $query;
  				$result = mysql_query($query,$db);
					if($result == 1)
					{
						echo "You have successfully registered with our site";
						echo "<br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/>";
					}
					else
					{
						echo "Email id is already used, Please try again";
						generate_form();
						
					}
 
			 }
	 }
 	 else
		{
		 	echo '<div class="error">  Sorry you have entered invalid security code,Please try again </div>';
		 	generate_form();
 	  }
 }
 else
 {
  	generate_form();
 }

 
 function generate_form()
 {
 global $email, $password,$short_name;
  // errors first
   echo "<h2> Registration form </h2>";
   echo "<p>Please input all the fields, and click register button </p>";
  
   echo "<form name='register_form' action='index.php?mode=register' method='POST'>";
   
   echo "Mandatory login information <br />";
   echo "<table border = 2 >  <tr><td width= '600px' > ";

   
   echo "<input type =hidden name=\"param\" value=\"register\"/>";
   echo "<input type =hidden name=\"postback\" value=\"something\"/>";
   if(isset($email))
   {
  	 	echo "<pre>Email ID  : <input type =\"text\"  name=email size = \"50\" value='$email' /> </pre> ";
   }
	 else
   {
   		echo "<pre>Email ID  : <input type =\"text\"  name=email size = \"50\" /> </pre> ";
   }
   if(isset($password))
   {
     echo "<pre>Password  : <input type =\"password\"   name=password  size = \"15\" value ='$password' /> </pre> ";
   }
   else
   {
     echo "<pre>Password  : <input type =\"password\"  name=password size = \"15\" /> </pre> ";
   }
   if(isset($short_name ))
	 {
      echo "<pre>Short name: <input type =\"text\"   name=shortname size = \"25\" value='$short_name' /> </pre> ";
   }
	 else
   {
   		echo "<pre>Short name: <input type =\"text\"  name=shortname size = \"25\" /> </pre> ";
   
   }
    echo '<pre>DOB       : <input name="dc" value="" size="11"  disabled= "true"><a href="javascript:void(0)" onclick="gfPop.fPopCalendar(document.register_form.dc);return false;" HIDEFOCUS><img name="popcal" align="absbottom" src="images/calbtn.gif" width="34" height="22" border="0" alt=""></a> </pre>';
    echo '<pre>Gender    : <input type="radio" name="sex" value="Male"> Male   <input type="radio" name="sex" value="Female"> Female<br /> <br/>';
   
   echo '<img src="./validation/captcha/image_validation.php?width=150&height=40&characters=5" />';
   echo '<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br />';
   echo "<pre>          <input type =submit name=\"Register\" value=\"Register\" /> </pre>";
   
  
  // echo '<input id="dateFromTxt" name="dateFromTxt" size="9" readonly="readonly"  type="text">';
  // echo "<a href='javascript:void(0)' onclick='if(self.gfPop)gfPop.fEndPop(\'hdnDate\'), 'dateFromTxt');return false;' hidefocus=''>";
  // echo " <img class='PopcalTrigger' src='images/calbtn.gif' alt='' align='absmiddle' border='0' height='22' width='34'></a> ";
  // echo "<script>  DaTe('dateFromTxt');</script> ";
	 echo " </td>";
   echo '</table>';
   
   echo "<bold> Profile Information </bold> <br />";
   echo "<table border = 2 >  <tr><td  width= '600px'> ";
   echo "<pre>First name: <input type =\"text\"  name=first_name size = \"25\" /> </pre> ";
   echo "<pre>Last name : <input type =\"text\"  name=last_name size = \"25\" /> </pre> ";
   echo "<pre>Profession: <SELECT  name='profession'>";
   echo ' <OPTION selected value="volunteer">Volunteer</OPTION>';
   echo ' <OPTION >Student</OPTION> ';
   echo '<OPTION>Information Technology</OPTION>';
   echo '<OPTION>NRI</OPTION>';
   echo '<OPTION>Patient</OPTION>';
   echo '<OPTION>Doctor</OPTION>';
   echo '<OPTION>NA</OPTION> ';
    
   echo '</SELECT> </pre> '; 
   echo 'Address :  <br />';
   echo "<pre>Address line 1  : <input type =\"text\"  name=address_line1 size = \"25\" /> Address line 2: <input type =\"text\"  name=address_line2 size = \"25\" /> </pre> ";
   echo "<pre>Address line 3  : <input type =\"text\"  name=address_line3 size = \"25\" /> City          : <input type =\"text\"  name=city size = \"25\" /> </pre> ";
   echo "<pre>State           : <input type =\"text\"  name=state size = \"25\" /> Country       : <input type =\"text\"  name=country size = \"25\" /> </pre> ";
   echo "<pre>PIN\ZIP code    : <input type =\"text\"  name=pin size = \"15\" /> </pre> ";
   echo "<pre>Contact number 1: <input type =\"text\"  name=phone1 size = \"15\" /> </pre> ";
   echo "<pre>Contact number 2: <input type =\"text\"  name=phone2 size = \"15\" /> </pre> ";
    echo "<pre>          <input type =submit name=\"Register with profile\" value=\"Register with profile\" /> </pre>";
   echo '</td></table>';
    echo "</form>";
    echo '<iframe width=168 height=190 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="ipopeng.htm" scrolling="no" frameborder="0" style="border:2px ridge; visibility:visible; z-index:999; position:absolute; left:-500px; top:0px;"></iframe>'; 
   ?>
   
<script language="JavaScript" type="text/javascript">

// function client_validate(form)
// {
//You should create the validator only after the definition of the HTML form
  var frmvalidator  = new Validator('register_form');
    
  frmvalidator.addValidation("email","maxlen=100");
  frmvalidator.addValidation("email","req");
  frmvalidator.addValidation("email","email");
  
  frmvalidator.addValidation("password","req","Please enter a valid password");
  frmvalidator.addValidation("password","maxlen=20", "Max length for password is 20");
  frmvalidator.addValidation("password","alpha");
  
  frmvalidator.addValidation("shortname","req");
  frmvalidator.addValidation("shortname","maxlen=50");
  
  frmvalidator.addValidation("dc","req","Please select a valid DOB");

  /*
  frmvalidator.addValidation("Phone","maxlen=50");
  frmvalidator.addValidation("Phone","numeric");
  
  frmvalidator.addValidation("Address","maxlen=50");
  frmvalidator.addValidation("Country","dontselect=0");
  */
//}
</script>
   <?php
   
 }
 
?>


</p>